<template>
  <view class="content">
    <u-cell-group>
      <u-swipe-action
        v-for="item in visitlist"
        :key="item.id"
        :autoClose="true"
      >
        <u-swipe-action-item
          :options="options2"
          @click="changeOperation"
          :name="item.id"
        >
          <view class="swipe-action u-border-top u-border-bottom">
            <view class="swipe-action__content">
              <u-cell
                :title="item.content"
                :value="item.business.nickname"
                :label="$u.timeFormat(item.createtime, 'yyyy年mm月dd日 hh:MM')"
                center
              ></u-cell>
            </view>
          </view>
        </u-swipe-action-item>
      </u-swipe-action>
    </u-cell-group>
    <u-button
      @click="add"
      :customStyle="btnStyle"
      color="#19BC9C"
      type="success"
      >添加回访记录</u-button
    >
    <u-modal
      :show="show"
      :content="content"
      :showCancelButton="true"
      @confirm="confirm"
      @cancel="show = false"
    ></u-modal>
    <u-toast ref="uToast"></u-toast>
  </view>
</template>
<script>
export default {
  data() {
    return {
      btnStyle: {
        width: "100%",
        position: "fixed",
        bottom: "0px",
      },
      visitlist: [],
      LoginAdmin: {},
      options2: [
        {
          text: "编辑",
          id: "edit",
          style: {
            backgroundColor: "#3c9cff",
          },
        },
        {
          text: "删除",
          id: "del",
          style: {
            backgroundColor: "#f56c6c",
          },
        },
      ],
      show: false,
      content: "确认是否删除当前回访记录?",
      id: 0,
    };
  },
  methods: {
    add() {
      this.$u.route("/pages/manage/visit/add/add");
    },
    async getVisitData() {
      let data = {
        adminid: this.LoginAdmin.id,
      };

      let result = await this.$u.api.manage.VisitIndex(data);

      if (result.code === 1) {
        this.visitlist = result.data;
      }
    },
  },
  onShow() {
    this.LoginAdmin = uni.getStorageSync("LoginAdmin")
      ? uni.getStorageSync("LoginAdmin")
      : {};

    this.getVisitData();
  },
};
</script>